<?php
class IndexController extends Vnf_Controller_Action {
    protected $_dir;
	function init() {
        parent::init();
        $this->view->translate = new Zend_Translate('tmx', BASE_DIR . '/translate/admin.tmx', 'en');
        $this->view->key = $key = $this->getParam('key', null);
    }

    public function indexAction() {

        $this->prepareData();

        //$this->view->title = "Shop Online - Lucky Asia";
        /*
        if ($this->view->showDefaultPage ) {
            $this->setLayout('firstpage');
            return;
        }
        */
        /*
        $defaultNamespace = new Zend_Session_Namespace('Default');
        if (isset($defaultNamespace->numberOfPageRequests)) {
            // this will show content normal.
            $defaultNamespace->numberOfPageRequests;
        } else {
            // this will show default page
            // first time
            $defaultNamespace->numberOfPageRequests = true;
        }
        */
        $this->setLayout(DEFAULT_LAYOUT);

        $currentPage = $this->view->currentPage;
        $template = @$currentPage['template'];

        //echo "index action";
        // print_r($currentPage);
//        echo "HHHHHHHHH--------";
        if ('' !=  $template && null != $template)
            $this->_helper->viewRenderer->renderScript($template);
            //exec()
//            $this->_helper->viewRenderer->renderScript('cms/list.phtml');
          //  return;
          
          
        $slide = new Page(); // slide banner
        $departmentID = 12;
        $this->view->slide = $slide->getRecords("thistable.DepartmentID = '$departmentID'  AND thistable.FeaturedYN = 'Yes' and thistable.ActiveYN = 'Yes'", "SortPriority DESC");
        
        
        // hot news
        $linkpage = new Page();
        $departmentID = 15;
        $this->view->linkpage = $linkpage->getRecords("thistable.DepartmentID = '$departmentID' AND thistable.FeaturedYN = 'Yes' and thistable.ActiveYN = 'Yes'", "SortPriority DESC", '5');
    }

    public function centerAction() {
        echo "<hr>This content output from centerAction";
        $this->_helper->viewRenderer->setViewScriptPathSpec('cms/detail.phtml');
    }
    public function headerAction() {
        $defaultNamespace = new Zend_Session_Namespace('Default');
        @$this->view->access = $defaultNamespace->access;
        $this->view->userLogged = $defaultNamespace->user;
        
        $category = new Category();

        $this->view->menu = $category->getMainMenu();
        
        $partnerID = $this->getParam('reff');
        if ($partnerID > 0) {
            $defaultNamespace = new Zend_Session_Namespace('Default');
            $defaultNamespace->reff = $partnerID;
            
            $objPartner = new Partners();
            
            $objPartner->increaseValue("HitNumber", 1, "PartnerID = '$partnerID'");
        }
        
    }

    public function footernotuniformAction() {
    }
    public function footerAction() {
        $this->view->notshow = (int)$this->getParam('showcur', 1);
        
        $defaultNamespace = new Zend_Session_Namespace('Default');
        @$this->view->access = $defaultNamespace->access;
        $this->view->alertMessage = "";
        if ($defaultNamespace->access) {
            $this->view->userLogged = $userLogged = $defaultNamespace->user;
            
            /*
            $objUser = new User();
            $pkUser = $objUser->getPrimaryKey();
            
            $userLog = $objUser->fetchRow("$pkUser = '" . $userLogged['category_id'] . "'");
            if (count($userLog) > 0) {
                $this->view->alertMessage = $userLog->note;
                $objUser->emptyField('note', "" , "$pkUser = '" . $userLogged['category_id'] . "'");
            }
            */
        }
    }

    public function leftAction() {
        $this->prepareData();
        // set another template
        // $this->_helper->viewRenderer->setScriptAction('test');
        // :controller/:action.:suffix

        // render to another content
        //$this->_helper->viewRenderer->setViewScriptPathSpec('cms/detail.phtml');


        $currentChild = $this->view->currentChild;

        if (count($currentChild) > 0)
            $this->view->leftMenuID = $this->view->currentPageID;
        else {
            $currentPage = $this->view->currentPage;
//            print_r($currentPage);
            $this->view->leftMenuID = $currentPage['parent'];
        }
    }

    /*public function rightAction() {
    }*/

    public function blockcmsAction() {
        @$this->view->blockParams = $params = $this->_getAllParams();
        @$this->view->module = $params['module'];
        @$this->view->controller = $params['controller'];
        @$this->view->action = $params['action'];
        @$this->view->name = $name = $params['id'];
        @$this->view->showContent = $showContent = $params['showContent'];
        @$this->view->content = $showContent = $params['content'];
        @$this->view->title = $showContent = $params['title'];

        //
        $isBlockNameAldreadyExists = false;
        // get all block has been register

        $manageBlockCms = Vnf::getBlockCms();

        // check id of block has exists in this page
        if (!array_key_exists($name, $manageBlockCms)) {
            $manageBlockCms[$name] = array('id' => $name);
            Zend_Registry::set('blockcms', $manageBlockCms);
        } else {
            $isBlockNameAldreadyExists = true;
            echo "<br>$name already exists<br>";
        }
        $this->view->isBlockNameAldreadyExists = $isBlockNameAldreadyExists;
    }

    public function endcmsAction() {
        Zend_Registry::set('blockcms', array());
    }

    public function translateAction() {
        $translate = new Zend_Translate('tmx', PATH_LANG_MODULE . 'items/english.tmx', 'en');
//        echo $translate->
    }

    public function listThumbnailsAction() {
		$this->listAction();
	}

    public function productcontentAction() {
        $this->view->cid = $cid = $this->_request->getParam('cid', 0);
    }

    public function listAction() {

        //$this->processLoginAction();
        // get category id
        $this->view->key = $key = $this->getParam('key', null);
        $catID = $this->_request->getParam('cid', 0);
        $this->view->template = $template = $this->_request->getParam('template');
        $currentPage = $this->view->currentPageID;

        // get child page
        $pageWithSubPage = $this->view->currentChild;
        // join current page
        //$pageWithSubPage[] = $currentPage;//['category_id'];
        $pageWithSubPage[] = $catID;//['category_id'];
        // parse to string
        $strPageWithSubPage = implode(',', $pageWithSubPage);

        //if ($catID > 0) {
            $where = "thistable.category_id in ($strPageWithSubPage)";
            
            if ($key) {
                $where .= " AND (thistable.item_title like '%$key%' OR thistable.item_description like '%$key%' OR thistable.item_short_description like '%$key%')";
            }

            $showallcat = $this->_request->getParam('all', 0);
            if ($showallcat) {
                $where = null;
            }
            //echo $where;

            $objItem = new Item();

            $this->view->totalRecords = $totalRecords = $objItem->getTotalRecords("$where");

            $currentPaging = (int) $this->_request->getParam('page', 1);
            $currentPaging--;
            $numberPageView = 5;
            $recordsPerPage = (int) $this->_request->getParam('records', 10);
            $recordsPerPage = $recordsPerPage > 0? $recordsPerPage:10;
            $totalPages = ceil($totalRecords/$recordsPerPage);
            $this->view->pages = $totalPages;

            //echo $currentPage;
            $link =  BASE_PATH . '/' . CURR_APP . "?pid=$currentPage&all=$showallcat";
            if ($key) {
                $link .= "&key=".htmlspecialchars($key);
            }
            $tagID = "showbycat";
            $startRecord = $recordsPerPage * $currentPaging;
            //$order = 'CommentID DESC';
            $class = "paging";

            $paging = new Paging();
            $this->view->paging = $paging->getPaging($currentPaging + 1, $totalPages, $link, $numberPageView, $tagID, $class,'false');

            $pk = $objItem->getPrimaryKey();
            $items = $objItem->getRecords($where, "$pk DESC", $recordsPerPage, $recordsPerPage * $currentPaging);

            //print_r($items);
            //get all items in current page and sub page
            //$items = $objItem->getRecords("$where", "item_id DESC");

            $this->view->allItems = $items;
            
        //}
    }

    public function detailAction() {
        $this->setLayout(DEFAULT_LAYOUT);
        $this->prepareData();
        $id = $this->_request->getParam('id', 0);
        $this->view->id = $id;
    }

    /*
     * $id is a items of categories
     */
    private function checkCapBac($value_capbac_item) {
        $defaultSession = new Zend_Session_Namespace('Default');
        if ($value_capbac_item > 0) {
            if (isset($defaultSession->user)) {
                $user_capbac_value = $defaultSession->user['value'];
                if ($user_capbac_value < $value_capbac_item) {
                    $this->_redirect("index/index/preparelogin");
                }
            } else {
                $this->_redirect("index/index/preparelogin");
            }
        }
    }

    public function detailContentAction() {
        // get category id
        $this->view->itemID = $itemID = $this->_request->getParam('id', 0);

        if ($itemID > 0) {
            $objItem = new Item();
            $items = $objItem->getRecords("item_id <= '$itemID'", "item_id DESC", 11);
            $this->view->newItems = $newItems = $objItem->getRecords("item_id > '$itemID'", "item_id DESC", 10);
            
            if (count($items) > 0) {
                $item = $items[0]->toArray();
                //$this->checkCapBac($item['value']);
                if ($item) {
                    $this->view->item = $item;
                    $this->view->currentPageID = $item['category_id'];
                    $this->prepareData();
                }
                $this->view->items = $items;
                
                //get all discussion of news
                $discussion = new ItemDiscussion();
                
                $where = "thistable.item_id = '$itemID'";
                $order = "thistable.datecreated ASC";
                $this->view->discussion = $discussion->getRecords($where, $order);
                
                $tag = $item['tag'];
                if ($tag != ",") {
                    $tag = trim($tag, ",");
                    $new_tag = strtoupper(preg_replace('/,+/', '|', $tag));
                    $new_tag = strtoupper(preg_replace('/\s+/', '', $new_tag));
                    $this->view->relateItems = $objItem->getRecords("thistable.item_id != '$itemID' AND UPPER(thistable.tag) REGEXP '[[:<:]]($new_tag)[[:>:]]'", "item_id DESC", 10);
                }
            }
        }

        //print_r($_SERVER);

        $currentPage = $this->view->currentPage;

        if ($currentPage['template']) {
            $detail = explode('/', $currentPage['template']);
            if (isset($detail[1])) {
                $currModule = $this->_request->getModuleName();
                $modulesPath = SRC_PATH . '/' . CURR_APP_PATH . '/modules/' . $currModule.'/views/scripts/';
                $subTemplate = $detail[0] . '/detail-page-' . $detail[1];
                if (is_file($modulesPath . $subTemplate)) {
                    $this->_helper->viewRenderer->renderScript($subTemplate);
                } else {
                    // do nothing
                    // show by default detail page
                }
            }
        }
    }

    public function lastestitemsAction() {
            $objItem = new Item();

            $pk = $objItem->getPrimaryKey();
            $items = $objItem->getRecords(null, "$pk DESC", 20);

            // get all items in current page and sub page
//            $items = $objItem->getRecords("$where", "item_id DESC");

            $this->view->lastestItems = $items;

    }

    public function prepareData() {
        $params = $this->_request->getParams();
        //$currentPageID = 0;
        $category = new Category();
        /*
        $this->view->allFullFriendlyUrl = $allFullFriendlyUrl = $category->getAllFullFriendlyUrl();

        //echo "-----" . stristr($_SERVER['REDIRECT_URL'], BASE_URL);
        if(stristr($_SERVER['REDIRECT_URL'], BASE_URL)) {
            $friendlyUrl = substr($_SERVER['REDIRECT_URL'], strlen(BASE_URL));
            $allFullFriendlyUrl = $this->view->allFullFriendlyUrl;

            //print_r($allFullFriendlyUrl);
            if (isset($allFullFriendlyUrl[$friendlyUrl])) {
                $currentPageID = $allFullFriendlyUrl[$friendlyUrl];
                $this->view->currentPageID = $currentPageID;
            }
        }

        */
        $currentPageID = $this->getParam('pid', $this->view->currentPageID);
        $id = $this->getParam('id', 0); // item id

        // get default content if has not page transfer
        $showDefaultPage = false;
        $getSubPage = false;
        if ($currentPageID <= 0) {
            $root = $category->getRoot();
            $currentPageID = $root->category_id;
            if ($id == 0) $getSubPage = true; // item id

            $this->view->showDefaultPage = $showDefaultPage = true;
        }
        $this->view->currentPageID =  $currentPageID;


        $allCategory = $category->getCacheOfCategory();

        $this->view->allCategory = $allCategory;

        $currentPage = $allCategory[$currentPageID];
        $categoryPath = $currentPage['all_parent']!=""?$currentPage['all_parent'].",".$currentPageID : $currentPageID;

        $this->view->categoryPath = explode(',', $categoryPath);
        if (!is_array($this->view->categoryPath)) {
            $this->view->categoryPath = array();
        }
        $this->view->currentPage = $currentPage;

//        print_r($currentPage);

        $childPage = array();
        @$childPage = $currentPage['children'];
        $this->view->currentChild = $childPage;

        if ($getSubPage) {
            if (isset($childPage[0])) {
                $this->view->currentPageID =  $currentPageID = $childPage[0];
                $this->view->currentPage = $allCategory[$currentPageID];
            }
        }

        $paramsTransfer = $params;
        unset($paramsTransfer['loginform']);
        if (isset($paramsTransfer['lastparams'])) {
            $this->view->paramsEncode = $paramsTransfer['lastparams'];
            unset($paramsTransfer['lastparams']);
        } else {
            $this->view->paramsEncode = Zend_Json::encode($paramsTransfer);
        }


    }
    
    public function mediaAction() {
        $this->setLayout(DEFAULT_LAYOUT);
        $this->prepareData();

        $this->view->id = $this->_request->getParam('id', 0);
    }

    public function mediacontentAction() {
        $itemID = $this->_request->getParam('id', 0);
        if ($itemID > 0) {
            $objItem = new Item();
            $item = $objItem->fetchRow("item_id = '$itemID'");

            if ($item) {
                $this->view->item = $item;
                $this->view->currentPageID = $item->category_id;
                $this->prepareData();
            }
        }
    }

    public function contentAction() {

    }

    public function contentloginAction() {
        $this->processLoginAction();
    }

    public function listloginAction() {
        $this->processLoginAction();
        $this->listAction();
    }

    public function randomitemAction() {
        $objItem = new Item();
        $where = "top_product = 1";
        $this->view->randomItems = $objItem->getRecords($where, "rand()", 10);
    }

    public function contactAction() {
        $this->setLayout(DEFAULT_LAYOUT);
        $this->prepareData();
        //$template = "cms/page-content.phtml";
        //$this->_helper->viewRenderer->renderScript($template);
            $template = "cms/page-content.phtml";
            //$this->_helper->viewRenderer->renderScript($template);
        if (!$this->_request->isPost()) {
            $mail = new Zend_Mail("UTF-8");
            $params = $this->_request->getParams();

            $this->view->firstName = $firstName = @$params['fullname'];
            $this->view->address = $address = @$params['address'];
            $this->view->email = $email = @$params['email'];
            $this->view->phone = $phone = @$params['phone'];
            $this->view->comments = $comments = @$params['comments'];

            /*
            if ($email) {
                $mail->setBodyHtml("$comments<br><br>$firstName <br><br>$phone");
                $mail->setFrom($email, "$firstName");
                $mail->addTo('ptp285@yahoo.com', 'NDTCO ');
                $mail->addCc('ptp285@gmail.com', 'NDTCO ');
                //$mail->addTo('director@ndtco.net', 'NDTCO ');
                //$mail->addCc('huy@ndtco.net', 'NDTCO ');
                $mail->setSubject('NDTCO - Contact form');
                $mail->send();
            }
            */
        }
        $this->view->message = "<div style='padding: 10px;'>Your message  has been sent. Thanks for contact us. We will contact you soon!</div>";
    }
    public function rightAction() {
    }

    public function homepageAction() {

        //$strID = "29,18";
        $strID = null;
        $objItem = new Item();
        $this->view->itemEachCat = $items = $objItem->getItemEachCat($strID, 3);
        //$this->_helper->viewRenderer->setViewScriptPathSpec('index/listitemseachcat.phtml');
    }

    public function prepareloginAction() {
        $this->prepareData();
        $this->setLayout(DEFAULT_LAYOUT);
        $this->view->translate = new Zend_Translate('tmx', BASE_DIR . '/translate/admin.tmx', 'en');
        $this->view->loginpage = 1;
    }
    
    public function loginAction() {
    }
    
    public function logininnerAction() {
        $this->processLoginAction();
    }
    
    public function logoutAction() {
        $defaultNamespace = new Zend_Session_Namespace('Default');
        $defaultNamespace->access = false;
        $defaultNamespace->user = array();
        $this->_redirect("index");
    }
    
    public function listsubcatAction() {
        $catid = (int)$this->_request->getParam('cid');
        $this->view->catid = $catid;

    }
    public function readAction() {
        //$base = '..';
        //$album = 2;
        //$dir = "/public/upload/photoalbum";
        //$album = 5;
        //$dir = "/public/upload/hinhngoaicanh";
        //$album = 3;
        //$dir = "/public/upload/hinhlecuoi";
        /*
        $arr_cat = array(
            85, 86,87,88,
            106,107,108,109,110,111,112,
            94,95,96,97,
            113,114,115,116,117,118,119
        );
        $array_path = array(
            '/mp3/thoatvongtucluy','/mp3/thapdaidetu','/mp3/phuocnghiep','/mp3/NiemQuanTheAm',
            '/mp3/NhungCanhHoaDam','/mp3/KinhPhapBaoDan','/mp3/KhiNaoChimSapBay','/mp3/hoavouu','/mp3/chanhVaTa','/mp3/bodedaopham','/mp3/38PhapHanhPhuc',
            '/song/VulanNhoMe','/song/VuLanNhacKhuc1','/song/TiengChuongThucTinh','/song/TuBiCa',
            '/song/thang7vulan','/song/SamHoi','/song/NgonLuaTuBi','/song/MuoiPhuongHoaNo','/song/MuaSenNo','/song/DuongXuaMayTrang','/song/all',
        );
        */

   die;
$folders = array(
    'ChungDaoCa',
    'Luat Truong Hang',
    'Luoc Su Duc Phat Thich Ca',
);
$category = new Category();
$objItem = new Item();

foreach($folders as $folder):
//die;

$cat_id = $category->insert(
    array(
        'admin_title' => str_replace('quyen', 'Quyển',$folder),
        'template_id' => 11,
        'main_menu' => 0,
        'status' => 1,
        'parent' => 49
    )
);

$path_dir_1 = "/public/upload/". $folder;
$realDir_1 = BASE_DIR . $path_dir_1;

if ($handle_1 = opendir($realDir_1)) {
    while (false !== ($dir_1 = readdir($handle_1))) {
        if ($dir_1 != "." && $dir_1 != "..") {
$sub_cat_id = $category->insert(
    array(
        'admin_title' => str_replace('so', 'số',str_replace('bai', 'Chương', $dir_1)),
        'template_id' => 2,
        'main_menu' => 0,
        'status' => 0,
        'parent' => $cat_id
    )
);
//die;
            $dir = $path_dir_1 . "/" . $dir_1;
            $realDir = BASE_DIR . $dir;
            if ($handle = opendir($realDir)) {
                //echo "Vao";
                $count = 1;
                while (false !== ($file = readdir($handle))) {
                    if ($file != "." && $file != "..") {
                        $pos = stripos( $file, '.');
                        //$title =  substr($file, 0, $pos);
                        $title =  "Trang " . $count++;//str_replace('.jpg', '', $file);
                        //$title =  "" . str_replace('.jpg', '', $file);
                        echo "<br>$title - " . $path = "$dir/$file";
                        $data = array(
                            'item_title' => $title,
                            'category_id' => $sub_cat_id,
                            'item_image' => $path,
                            'item_short_description' => $title,
                            'item_description' => $title,
                            'item_status' => 1,
                        );
                        $objItem->insert($data);
                    }
                }
                closedir($handle);
            } else {
                echo "KO Vao";
            }
        }
    }
}
echo "<br>FINISH - " . $folder;
endforeach; // for folder

echo "<br><br>FINISH";
        die;
    }
    
    public function gallery2Action(){
        $this->listAction();
    }
    public function galleryAction(){
        $this->listAction();
    }
    
    public function getcatAction() {
        $category = new Category();
        
        $pk = $category->getPrimarykey();
        $where = "parent = 72";

        $this->view->allCats = $category->getAllChildByCatId(72);
        
        //print_r($cats);
        //die;
    }
    public function slideAction() {
    }
    
    public function newshomeAction() {
        
        $config = Vnf::getConfigs('conf');
        $this->view->news_id = $news_id = @$config->news_id;
        

        if ($news_id > 0) {
            $item = new Item();            
            $pk = $item->getPrimaryKey();

            // get news of this categor and sub categories
            $allCategory = $this->view->allCategory;
            @$newsCat = $allCategory[$news_id];
            $pageWithSubPage = array();
            @$pageWithSubPage = $newsCat['children'];
            // join current page
            //$pageWithSubPage[] = $currentPage;//['category_id'];
            $pageWithSubPage[] = $news_id;//['category_id'];
            // parse to string
            $strPageWithSubPage = implode(',', $pageWithSubPage);

            $where = "thistable.category_id in ($strPageWithSubPage)";

            //$where = "thistable.category_id = '$news_id'";
            //$where = null;
            $order = "$pk DESC";
            $this->view->top_news = $top_news = $item->getRecords($where, $order, 11, 0);
        }
    }
    
    public function sponsorAction() {
        $config = Vnf::getConfigs('conf');
        $this->view->sponsor_id = $sponsor_id = @$config->nha_tai_tro;
    }
    
    public function partnerAction() {
        $config = Vnf::getConfigs('conf');
        $this->view->partner_id = $sponsor_id = @$config->doi_tac;
    }
    
    public function moreinfoAction() {
        $where = null;
        
        $obj_question = new Question();
        $pk = $obj_question->getPrimaryKey();
        $order = "$pk DESC";
        $this->view->lastestQuestions = $obj_question->getRecords("$where", $order, 10);
        
        $obj_tracnghiem = new Tracnghiem();
        $pk = $obj_tracnghiem->getPrimaryKey();
        $order = "$pk DESC";
        $this->view->lastestTracnghiem = $obj_tracnghiem->getRecords("$where", $order, 10);
        
        $obj_ans = new Ans();
        $obj_tailieu = new Tailieu();
        $obj_user = new User();
        
        $this->view->countQuestions = $obj_question->getTotalRecords();
        $this->view->countAns = $obj_ans->getTotalRecords();
        $this->view->countTracnghiem = $obj_tracnghiem->getTotalRecords();
        $this->view->countTailieu = $obj_tailieu->getTotalRecords();
        $this->view->countUser = $obj_user->getTotalRecords();
    }
    
    public function youtubeAction() {
        $yt = new Zend_Gdata_YouTube();
        $query = $yt->newVideoQuery();
        $query->videoQuery = 'ai ra xu hue';
        $query->startIndex = 0;
        $query->maxResults = 10;
        $query->orderBy = 'viewCount';

        echo $query->queryUrl . "\n";
        $videoFeed = $yt->getVideoFeed($query); 

        foreach ($videoFeed as $videoEntry) {
            print_r($videoEntry);
            /*
          echo "---------VIDEO----------\n";
          echo "Title: " . $videoEntry->mediaGroup->title->text . "\n";
          echo "\nDescription:\n";
          echo $videoEntry->mediaGroup->description->text;
          echo "\n\n\n";
          */
        }
        die;
    }
    
    public function submenuAction() {
        $this->prepareData();
        
        $this->view->translate = new Zend_Translate('tmx', BASE_DIR . '/translate/admin.tmx', 'en');
        $currentChild = $this->view->currentChild;
        $allCategory = $this->view->allCategory;

        if (count($currentChild) > 0) {
            //$this->_redirect("/?pid=" . $currentChild[0]);
        } else {
            $currentPage = $this->view->currentPage;
            $this->view->leftMenuID = $currentPage['parent'];
        }
        
    }
    
    
    public function adddiscussionAction() {
        $this->prepareData();
        $this->setLayout(DEFAULT_LAYOUT);
    }
    
    public function adddiscussioninnerAction() {
        $this->processLoginAction();
        $defaultNamespace = new Zend_Session_Namespace('Default');
        if (isset($defaultNamespace->access) && $defaultNamespace->access) {
            $id = (int)$this->getParam('id', 0);
            if ($id > 0) {
                $message = $this->getParam('message');
                if ($message) {
                    $defaultSession = new Zend_Session_Namespace('Default');
                    $userLogged = $defaultSession->user;
                    
                    $dissObj = new ItemDiscussion();
                    $current_time = date('Y-m-d H:i:s', time());
                    $data = array(
                        'item_id' => $id,
                        'user_id' => $userLogged['category_id'],
                        'description' => $message,
                        'datecreated' => $current_time,
                        'dateupdated' => $current_time,
                    );
                    $dissObj->insert($data);
                }
                $this->_redirect("index/index/detail?id=" . $id);
            }
        }
    }
    
    public function newsAction() {
        $config = Vnf::getConfigs('conf');
        $news_id = @$config->news_id;
        $this->_request->setParam('pid', $news_id);
        $this->prepareData();
        $this->setLayout(DEFAULT_LAYOUT);
    }
    
    public function searchnewsAction() {
        $config = Vnf::getConfigs('conf');
        $news_id = @$config->news_id;
        $this->_request->setParam('pid', $news_id);
        $this->prepareData();
    }
    
    public function popularitemsAction() {
        $objItem = new Item();

        $pk = $objItem->getPrimaryKey();
        $items = $objItem->getRecords(null, "count_buy DESC", 10);
        
        $this->view->popularItems = $items;
    }

    public function mostviewitemsAction() {
        $objItem = new Item();

        $pk = $objItem->getPrimaryKey();
        $items = $objItem->getRecords(null, "count_views DESC", 20);
        
        $this->view->mostViewItems = $items;
    }

    public function introhomepageAction() {
        $config = Vnf::getConfigs('conf');
        $this->view->intro = $intro = @$config->intro;
    }
    
    public function specialAction() {
        $config = Vnf::getConfigs('conf');
        $this->view->special = $special = (int)@$config->special;
        if($special > 0) {
            $objItem = new Item();
            $pk = $objItem->getPrimaryKey();
            
            $where = "thistable.category_id = '$special' AND thistable.item_status = 1";
            $order = "$pk DESC";
            $this->view->allSpecials = $allSpecials = $objItem->getRecords($where, $order, 10);
        }
    }
    
    public function locationservicesAction() {
        ;
    }
    public function galleryslideAction(){
        $this->view->cid = $cid = (int)$this->getParam('cid', 0);
    }
    
    public function menupdfcontentAction() {
    }
    public function viewpdfAction() {
        $this->view->pdf = $pdf = $this->getParam('file', '');
    }
    
    public function bannerAction() {
        
    }
    
    public function menuAction() {
        $objHeader = new Page();
        
        $this->view->headers = $headers = $objHeader->getRecords("thistable.DepartmentID = 10 AND thistable.ActiveYN = 'Yes'");
    }
    
    public function featureAction() {
        $objProduct = new Product();
        $where = "Featured = 'YES'";
        $this->view->featuredProducts = $objProduct->getRecords($where, null, 4);
    }

    public function pagecontentAction() {
        $this->setLayout(DEFAULT_LAYOUT);
        $this->prepareData();
    }
    public function pagecontentinnerAction() {
        
        $id = $this->getParam('id', 0);
        if ($id > 0) {
            $objPage = new Page();
            
            $where = "PageID = '$id'";
            $this->view->page = $page = $objPage->fetchRow($where);
        }
    }
}